﻿using System.Collections.Generic;

namespace Inovout.Land.Domain
{
    public class DiLei
    {
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string code;
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        public static DiLei GetGHDiLie(string code)
        {
            return ghDiLeiDictionary[code];
        }
        public bool IsLeaf
        {
            get { return items.Count == 0; }
        }
        private List<DiLei> items = new List<DiLei>();

        public List<DiLei> Items
        {
            get { return items; }
        }
        private DiLei parent;
        public DiLei Parent
        {
            get { return parent; }
            set { parent = value; }
        }
        private DiLei(string name, string code)
        {
            this.name = name;
            this.code = code;
        }
        static DiLei()
        {
            InitGHDiLei();
        }
        private static void InitGHDiLei()
        {
            InsertDiLeiDictionary(new DiLei("农用土","1"));
            InsertDiLeiDictionary(new DiLei("耕地", "11"));
            InsertDiLeiDictionary(new DiLei("水田", "111"));
            InsertDiLeiDictionary(new DiLei("水浇地", "112"));
            InsertDiLeiDictionary(new DiLei("旱地", "113"));
            InsertDiLeiDictionary(new DiLei("园地", "12"));
            InsertDiLeiDictionary(new DiLei("林地", "13"));
            InsertDiLeiDictionary(new DiLei("牧草地", "14"));
            InsertDiLeiDictionary(new DiLei("其他农用地", "15"));
            InsertDiLeiDictionary(new DiLei("设施农用地", "151"));
            InsertDiLeiDictionary(new DiLei("农村道路", "152"));
            InsertDiLeiDictionary(new DiLei("坑塘水面", "153"));
            InsertDiLeiDictionary(new DiLei("农田水利用地", "154"));
            InsertDiLeiDictionary(new DiLei("田坎", "155"));
            InsertDiLeiDictionary(new DiLei("建设用地", "2"));
            InsertDiLeiDictionary(new DiLei("城乡建设用地", "21"));
            InsertDiLeiDictionary(new DiLei("城市用地", "211"));
            InsertDiLeiDictionary(new DiLei("建制镇用地", "212"));
            InsertDiLeiDictionary(new DiLei("农村居民点用地", "213"));
            InsertDiLeiDictionary(new DiLei("采矿用地", "214"));
            InsertDiLeiDictionary(new DiLei("其他独立建设用地", "215"));
            InsertDiLeiDictionary(new DiLei("交通水利用地", "22"));
            InsertDiLeiDictionary(new DiLei("铁路用地", "221"));
            InsertDiLeiDictionary(new DiLei("公路用地", "222"));
            InsertDiLeiDictionary(new DiLei("民用机场用地", "223"));
            InsertDiLeiDictionary(new DiLei("港口码头用地", "224"));
            InsertDiLeiDictionary(new DiLei("管道运输用地", "225"));
            InsertDiLeiDictionary(new DiLei("水库水面", "226"));
            InsertDiLeiDictionary(new DiLei("水工建筑用地", "227"));
            InsertDiLeiDictionary(new DiLei("其他建设用地", "23"));
            InsertDiLeiDictionary(new DiLei("风景名胜设施用地", "231"));
            InsertDiLeiDictionary(new DiLei("特殊用地", "232"));
            InsertDiLeiDictionary(new DiLei("盐田", "233"));
            InsertDiLeiDictionary(new DiLei("其他土地", "3"));
            InsertDiLeiDictionary(new DiLei("水域", "31"));
            InsertDiLeiDictionary(new DiLei("河流水面", "311"));
            InsertDiLeiDictionary(new DiLei("湖泊水面", "312"));
            InsertDiLeiDictionary(new DiLei("滩涂", "313"));
            InsertDiLeiDictionary(new DiLei("自然保留地", "32"));

            foreach(DiLei diLei in ghDiLeiDictionary.Values)
            {
                if (diLei.Code.Length > 1)
                {
                    DiLei parentDL= ghDiLeiDictionary[diLei.Code.Substring(0,diLei.Code.Length-1)];
                    diLei.Parent = parentDL;
                    parentDL.Items.Add(diLei);
                }
            }
        }
        private static void InsertDiLeiDictionary(DiLei diLei)
        {
            ghDiLeiDictionary.Add(diLei.Code, diLei);
        }

        private static Dictionary<string, DiLei> ghDiLeiDictionary = new Dictionary<string, DiLei>(); 

    }
}
